Skip to content

fix: remove arbitrary 0.1 OPG floor from LLM.ensure_opg_approval() — validate positive only#222

Open
amathxbt wants to merge 1 commit intoOpenGradient:mainfrom
amathxbt:fix/llm-ensure-opg-min-allowance-mismatch
Open

fix: remove arbitrary 0.1 OPG floor from LLM.ensure_opg_approval() — validate positive only#222
amathxbt wants to merge 1 commit intoOpenGradient:mainfrom
amathxbt:fix/llm-ensure-opg-min-allowance-mismatch

Conversation

@amathxbt
Copy link
Copy Markdown
Contributor

🐛 Bug: LLM.ensure_opg_approval() Rejects Valid min_allowance Values

File: src/opengradient/client/llm.pyLLM.ensure_opg_approval()

What's broken

LLM.ensure_opg_approval() enforces an arbitrary minimum of 0.1 OPG on the min_allowance parameter:

# llm.py line 218-219
if min_allowance < 0.1:
    raise ValueError("min_allowance must be at least 0.1.")

But the underlying opg_token.ensure_opg_approval() function has no such restriction — it accepts any positive value. This creates a split where:

  • Small-amount use cases (e.g., min_allowance=0.05) work fine when calling opg_token.ensure_opg_approval() directly
  • But calling llm.ensure_opg_approval(min_allowance=0.05) raises a ValueError that's not actually required by the protocol

This 0.1 floor is an undocumented internal constraint with no technical basis, and is inconsistent with PR #201 which changed the hint constant to reference 0.05 OPG.

Fix

Replace the arbitrary floor with a simple positive-number guard (the only invariant that actually matters):

if min_allowance <= 0:
    raise ValueError("min_allowance must be a positive number.")

Updated docstrings to remove references to the obsolete 0.1 minimum.

Impact

Before After
llm.ensure_opg_approval(min_allowance=0.05)ValueError Accepted; delegates validation to opg_token layer
LLM wrapper more restrictive than underlying function LLM wrapper consistent with underlying function
Confusing mismatch between layers Single source of truth for validation

Files Changed

  • src/opengradient/client/llm.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant